<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">

	</head>

	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form" lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">
							<div class="layui-form-item">
								<label class="layui-form-label">状态</label>
								<div class="layui-input-block on_off"></div>
							</div>

							<div class="layui-form-item">
								<div class="layui-form-inline" id="fid">
									<label class="layui-form-label">分类：</label>
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">活动名称</label>
								<div class="layui-input-block">
									<input type="text" name="name" placeholder="请输入活动名称" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">活动副标题</label>
								<div class="layui-input-block">
									<input type="text" name="title_cn" placeholder="请输入活动副标题" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">客户端</label>
								<div class="layui-input-block icon_type"></div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">排序</label>
								<div class="layui-input-block">
									<input type="text" name="oid" placeholder="请输入排序" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">封面主图</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal" id="icon_btn2">封面主图</button>
									<span>只上传一张即可</span>
									<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
										预览图：
										<div class="layui-upload-list upload_list" id="icon_box2">
											<!-- <li id="2222"><img class="layui-upload-img" src="https://lishuahuoban-1259416407.image.myqcloud.com/bdf35814c3be45df915e6fc19c3e72df.jpg" alt="https://lishuahuoban-1259416407.image.myqcloud.com/bdf35814c3be45df915e6fc19c3e72df.jpg"><i class="close_icon layui-icon layui-icon-close-fill"></i> <p class="success"> <i class="layui-icon layui-icon-ok-circle"></i> <i class="layui-icon layui-icon-refresh"></i> 上传成功</p></li> -->
										</div>
									</blockquote>
									<!-- <button type="button" class="layui-btn layui-btn-normal" onclick="choose(1)">上传图片</button>
									<ul class="show_img_ul" id="img"></ul> -->
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">轮播图片</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal" id="icon_btn">上传图片</button>
									<span>只上传一张即可</span>
									<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
										预览图：
										<div class="layui-upload-list upload_list" id="icon_box">
											<!-- <li id="2222"><img class="layui-upload-img" src="https://lishuahuoban-1259416407.image.myqcloud.com/bdf35814c3be45df915e6fc19c3e72df.jpg" alt="https://lishuahuoban-1259416407.image.myqcloud.com/bdf35814c3be45df915e6fc19c3e72df.jpg"><i class="close_icon layui-icon layui-icon-close-fill"></i> <p class="success"> <i class="layui-icon layui-icon-ok-circle"></i> <i class="layui-icon layui-icon-refresh"></i> 上传成功</p></li> -->
										</div>
									</blockquote>
									<!-- <button type="button" class="layui-btn layui-btn-normal" onclick="choose(1)">上传图片</button>
									<ul class="show_img_ul" id="img"></ul> -->
								</div>
							</div>
							
							
							
							<div class="layui-form-item">
								<label class="layui-form-label">简介</label>
								<div class="layui-input-block">
									<input type="text" name="intro" placeholder="请输入简介" autocomplete="off" class="layui-input">
								</div>
							</div>  
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">公益内容<span style="color: red;">*</span></label>
									<div class="layui-input-block">
										<textarea class="layui-textarea layui-hide" name="请输入公益内容" lay-verify="content" id="demo_editor"></textarea>
									</div>
								</div>
							</div>
							
							<div class="layui-form-item upvideo">
								<label class="layui-form-label">视频</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal upimgbtn" onclick="choose(2)">上传视频</button>
									<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
										预览视频：
										<div class="layui-upload-list upload_list" id="shipin_box">
											<ul class="show_img_ul" id="video"></ul>
										</div>
									</blockquote>

								</div>
							</div>
					        <div class="layui-form-item">
								<label class="layui-form-label">受益对象</label>
								<div class="layui-input-block">
									<input type="text" name="target" placeholder="请输入受益对象" autocomplete="off" class="layui-input">
								</div>
							</div>
					        <div class="layui-form-item">
								<label class="layui-form-label">目标金额</label>
								<div class="layui-input-block">
									<input type="text" name="target_amount" placeholder="请输入目标金额" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">筹款用途</label>
								<div class="layui-input-block">
									<input type="text" name="purposes" placeholder="请输入筹款用途" autocomplete="off" class="layui-input">
								</div>
							</div> 
							<div class="layui-form-item">
								<label class="layui-form-label">剩余款项处理</label>
								<div class="layui-input-block">
									<input type="text" name="executing" placeholder="请输入剩余款项处理" autocomplete="off" class="layui-input">
								</div>
							</div> 
							<div class="layui-form-item">
								<label class="layui-form-label">发票说明</label>
								<div class="layui-input-block">
									<input type="text" name="invoice_shows" placeholder="请输入发票说明" autocomplete="off" class="layui-input">
								</div>
							</div> 
							<div class="layui-form-item">
								<label class="layui-form-label">备案编号</label>
								<div class="layui-input-block">
									<input type="text" name="record_number" placeholder="请输入备案编号" autocomplete="off" class="layui-input">
								</div>
							</div>   
							<div class="layui-form-item">
								<label class="layui-form-label">备注</label>
								<div class="layui-input-block">
									<input type="text" name="notes" placeholder="备注" autocomplete="off" class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">开始时间</label>
								<div class="layui-input-block">
									<input type="text" name="start_time" placeholder="开始时间" id="start_time"  autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">结束时间</label>
								<div class="layui-input-block">
									<input type="text" name="end_time" placeholder="结束时间" id="end_time"  autocomplete="off" class="layui-input">
								</div>
							</div>

						</div>
					</div> 
					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
								<button class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../js/jquery.min.js"></script>
		<script src="../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../js/common.js"></script>
		<script>
			var _data = {
				id: getParam('id'),
				type: ''
			}

			layui.config({
				base: '../../../layuiadmin/' //静态资源所在路径
			}).extend({
				tinymce: '../tinymce/tinymce', //主入口模块 
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate','tinymce','layedit','uploadnew'], function() {
				var $ = layui.$,
					admin = layui.admin,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					tinymce = layui.tinymce,
					uploadnew = layui.uploadnew,
					layedit = layui.layedit,
					form = layui.form;
		
				var maplist = JSON.parse(localStorage.getItem('lsmap')),
					img_arr1 = [];
				var img_arr2 = [];
				
				on_off_show('radio')
				icon_type_show('checkbox')
				
				  //日期时间选择器
			    laydate.render({
			      elem: '#start_time'
			      ,type: 'datetime'
			    }); 
			      //日期时间选择器
			    laydate.render({
			      elem: '#end_time'
			      ,type: 'datetime'
			    }); 
			    
			    /* 主图上传 */
				var img_option = {
					btnelem: '#icon_btn',
					filebox: '#icon_box',
					url: server.upimg,
				}
				/* 主图2上传 */
				var img_option2 = {
					btnelem: '#icon_btn2',
					filebox: '#icon_box2',
					url: server.upimg,
				}
				uploadnew.initupload(img_option,1)
				uploadnew.initupload(img_option2,1) 
				
			    var edit = tinymce.render({
					elem: "#demo_editor",
					height: 600
				}); 
				layedit.set({});
				var indexbuild = layedit.build('demo_editor1'); //建立编辑器
				
				
				//监听提交
				form.on('submit(demo1)', function(data) {
					var data = data.field;
					_data = Object.assign(_data, data);
					console.log(data)
					for (item in data){ 
						if(/^t/.test(item)){
							if(item.substr(0,4) == 'type'){
								_data.type += data[item]+','
								console.log(item)
								console.log(data[item])
							} 
						} 
					} 
					_data.type = (_data.type.substring(_data.type.length-1) == ',') ? _data.type.substring(0,_data.type.length-1) : _data.type; 
					
					_data.pic = uploadnew.initupload(img_option,3).join(',')
					_data.img = uploadnew.initupload(img_option2,3).join(',')
					_data.video_url = img_arr2.join(',');
					_data.content = edit.getContent()
					layer.confirm('确定提交数据？', function() {
						loading();
						if(_data.id) {
							submitdata(server.welfare_activities_edit);
						} else {
							delete _data.id;
							submitdata(server.welfare_activities_insert);
						}
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});

				$.ajax({
					url: server.welfare_activities_tree,
					type: 'post',
					async: false,
					dataType: 'json',
					success: function(data) {
						if(data.code == '0') {
							var data = data.welfare_activities.data
							var html = '';
							html += '<div class="layui-input-inline">';
							html += ' <select lay-search="" lay-filter="fid" lay-verify="type" name="fid" >';
							html += '  <option value="">请选择</option>';
							for(var i = 0; i < data.length; i++) {
								html += ' <option value=' + data[i].id + '>' + data[i].name + '</option>';
							}
							html += ' </select>';
							html += '</div>';

							$('#fid').append(html);
							form.render('select')
						}
					},
					'error': function() {

					}
				})

				if(_data.id) {
					initdata();
				}

				function submitdata(_url) {
					$.post(_url, _data, function(res, status) {
						if(status == 'success') {
							if(res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.msg(res.msg);
								layer.closeAll('loading');
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}  
				function initdata() {
					$.get(server.welfare_activities_detail, _data, function(res, status) {
						if(status == 'success') {
							if(res.code == 0) {
								var data = res.welfare_activities 
								img_option.filedata = data.data.pic ? data.data.pic : ''
								img_option2.filedata = data.data.img ? data.data.img : ''
								data.data.pic ? uploadnew.initupload(img_option,2) : '',
								data.data.img ? uploadnew.initupload(img_option2,2) : '', 
								console.log(data.data.video_url)
								data.data.video_url ? createli(data.data.video_url, 'video', '2') : '';
								
								$(".on_off input[value=" + data.data.status + "]").attr("checked", true)
								//$('.fid').val(data.da); 
								
								if(data.data.type){
									var type_arr = data.data.type.split(',')
									for (var i = 0; i < type_arr.length; i++) {
										$(".icon_type input[value=" + type_arr[i] + "]").attr("checked", true)
									}
								}
								
								setTimeout(function() {
									edit.setContent(data.data.content);
									layedit.setContent(indexbuild, data.data.content);　　
								}, 1000);　
								form.val("test_detail", data.data);
								form.render();
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}
				window.choose = function(data) {
					layer.open({
						type: 2,
						title: '上传文件',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['600px', '400px'],
						content: 'up_report.html?type=' + data,
						end: function() {},
						success: function() {}
					});
				}
				window.getimg = function(data, type) {
					if(data) {
						switch(type) {
							case '1':
								createli(data, 'img', type)
								break;
							case '2':
								createli(data, 'video', type)
								break;
							default:
								break;
						}
					}
				}
				function createli(data, dom, type) {
					var lihtml = '';
					switch(type) {
						case '1':
							if(data.indexOf(',') == -1) {
								img_arr1.splice(0, 1, data)
							} else {
								for(var i = 0; i < data.split(',').length; i++) {
									img_arr1.push(data.split(',')[i])
								}
							}
							for(var i = 0; i < img_arr1.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<img src=' + img_arr1[i] + ' >' +
									'<p onclick="delimg(' + i + ',1,this)">删除</p>' +
									'</li>'
							}
							break;
						case '2':
							if(data.indexOf(',') == -1) {
								img_arr2.splice(0, 1, data)
							} else {
								for(var i = 0; i < data.split(',').length; i++) {
									img_arr2.push(data.split(',')[i])
								}
							}
							for(var i = 0; i < img_arr2.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<video controls="controls" id="video{{index}}" width="320" height="240"><source src=' + img_arr2[i] + ' type="video/ogg" /><source src=' + img_arr2[i] + ' video/mp4" /></video>' +
									'<p onclick="delimg(' + i + ',2,this)">删除</p>' +
									'</li>'
							}
							break;
						default:
							break;
					}
					$('#' + dom).html(lihtml);
				}
				window.delimg = function(i, type, _self) {
					var _type = String(type)
					layer.confirm('确定要删除视频？', function(index) {
						switch (_type) {
							case '1':
								img_arr2.splice(i, 1)
								break;
							default:
								break;
						}
						$(_self).parent().remove();
						layer.close(index)
					}, function() {
						layer.msg('取消操作');
					});
				}
			});
		</script>
	</body>

</html>